<!DOCTYPE html>
<html>

<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
	<style type="text/css">
		body,
		html,
		#allmap {
			width: 100%;
			height: 100%;
			overflow: hidden;
			margin: 0;
			font-family: "微软雅黑";
		}
	</style>
	<script type="text/javascript"
		src="http://api.map.baidu.com/api?v=2.0&ak=UW6UNuQqKbT2HeZ0j1VBlEQ3OK5R21o7"></script>
	<title>地图展示</title>
</head>

<body>
	<div id="allmap"></div>
</body>

</html>
<!-- <script src="baiduTilesInfo.js"></script>  -->
<script src="qwebchannel.js"></script>
<script type="text/javascript">

	var webcom;
	new QWebChannel(qt.webChannelTransport, function (channel) {
		mw = channel.objects.window;
		webcom = channel.objects.webcom;
		window.foo = webcom;
		// webcom.content = "js调用";
		// webcom.jscallme();
	});

	// 百度地图API功能
	var map = new BMap.Map("allmap", { enableMapClick: false });// 创建Map实例，关闭底图可点功能
	var point = new BMap.Point(116.52, 39.79);
	map.centerAndZoom(point, 17);  // 初始化地图,设置中心点坐标和地图级别
	map.enableScrollWheelZoom(true);     //开启鼠标滚轮缩放


	//****添加缩放按钮
	var top_left_control = new BMap.ScaleControl({ anchor: BMAP_ANCHOR_TOP_LEFT });// 左上角，添加比例尺
	var top_left_navigation = new BMap.NavigationControl();  //左上角，添加默认缩放平移控件
	map.addControl(top_left_control);
	map.addControl(top_left_navigation);
	map.addControl(new BMap.OverviewMapControl());
	map.removeControl(new BMap.CopyrightControl());
	//添加地图类型控件
	map.addControl(new BMap.MapTypeControl({
		mapTypes: [
			BMAP_NORMAL_MAP,
			BMAP_HYBRID_MAP
		]
	}));
	//map.setCurrentCity("北京");


	var marker = new BMap.Marker(point);

	// 创建圆
	var circle = new BMap.Circle(point, 300, {
		strokeColor: 'blue',
		strokeWeight: 2,
		strokeOpacity: 0.5
	});

	// 添加覆盖物
	function addOverlay() {
		map.addOverlay(marker); // 增加点
		map.addOverlay(circle); // 增加圆
	}

	// 清除覆盖物
	function removeOverlay() {
		map.clearOverlays();
	}


	var myGeo = new BMap.Geocoder();
	map.addEventListener("click", function (e) {
		//mw.onRecvPostion(e.latlng.lng, e.latlng.lat);
		var pt = e.point;
		//alert(e.point.lng) //经度
		//alert(e.point.lat) //维度
		myGeo.getLocation(pt, function (rs) {
			var addComp = rs.addressComponents;
			var addres = addComp.province + addComp.city + addComp.district + addComp.street + addComp.streetNumber;
			webcom.mMouseClick = pt.lng + "," + pt.lat + ";" + addres;
			webcom.signalMouseClick // emit signals to C++
		});

	});


	function getPoint(address) {
		map.centerAndZoom(new BMap.Point(116.404, 39.915), 11);
		var myGeo = new BMap.Geocoder();
		// 将地址解析结果显示在地图上，并调整地图视野    
		myGeo.getPoint(address, function (point) {
			if (point) {
				alert(address);
				alert(point.lng);
			}
		}, "北京市");
	}

	function getPointCall(address, callback) {
		map.centerAndZoom(new BMap.Point(116.404, 39.915), 11);
		var myGeo = new BMap.Geocoder();

		// 将地址解析结果显示在地图上，并调整地图视野
		myGeo.getPoint(address, function (point) {
			if (point) {
				alert(address);
				alert(point.lng);
				// Call the callback function with the point
				callback(point);
			} else {
				console.error("Address not found: " + address);
				callback(null); // Call with null if the point is not found
			}
		}, "北京市");
	}


	let isEnableOrNot = true;
	function removeControl() {
		if (isEnableOrNot) {
			map.removeControl(top_left_control);
			map.removeControl(top_left_navigation);
			isEnableOrNot = false;
		} else {
			map.addControl(top_left_control);
			map.addControl(top_left_navigation);
			isEnableOrNot = true;
		}
	}

	var mapType = "BMAP_NORMAL_MAP";
	function setMapStyle() {

		if (mapType === "BMAP_NORMAL_MAP") {
			mapType = "BMAP_SATELLITE_MAP";
			map.setMapType(BMAP_SATELLITE_MAP);
		} else {
			mapType = "BMAP_NORMAL_MAP";
			map.setMapType(BMAP_NORMAL_MAP);
		}
	}

	function routePlanning(startAddress, endAddress, travelType) {
		if (travelType === "walking") {
			route = new BMap.WalkingRoute(map, {
				renderOptions: { map: map, panel: "r-result", autoViewport: true }
			});

			route.search(startAddress, endAddress);

		} else if (travelType === "bicycling") {
			var riding = new BMap.RidingRoute(map, {
				renderOptions: {
					map: map,
					autoViewport: true
				}
			});

			var start = new BMap.Point(116.310791, 40.003419);
			var end = new BMap.Point(116.386419, 40.003519);
			riding.search(start, end);
		} else if (travelType === "driving") {
			var point = new BMap.Point(116.51397, 39.73517);
			map.centerAndZoom(point, 11);
			map.enableScrollWheelZoom(true);


			var driving = new BMap.DrivingRoute(map, {
				renderOptions: {
					map: map,
					panel: "results",
					autoViewport: true,
				}
			})

			driving.search(startAddress, endAddress);

		} else if (travelType === "transit") {

			var transit = new BMap.TransitRoute(map, {
				renderOptions: { map: map, panel: "results" }
			});
			transit.search(startAddress, endAddress);
		} else {
			console.error("Invalid travel type: " + travelType);
			return;
		}
	}

	//**********************自定义函数     x=long , y=lat  ,BD09坐标系

	//添加点标注
	function add_Point(x, y) {
		var pt = new BMap.Point(x, y);
		var marker = new BMap.Marker(pt);
		map.addOverlay(marker);
		//map.clearOverlays();
		// map.setCenter(data.points[0]);   
		//map.removeOverlay(marker);               
	}
	//添加 .ico
	function add_Ico(x, y) {
		// var myIcon = new BMap.Icon("airplane48.ico", new BMap.Size(-0.0000001,-0.0000001));
		// var marker = new BMap.Marker(pt,{icon:myIcon});  
		var pt = new BMap.Point(x, y);
		var marker = new BMap.Marker(pt, {
			icon: new BMap.Icon("airplane48.ico", new BMap.Size(-0.0000001, -0.0000001), {
				anchor: new BMap.Size(2, 3)  //偏移
			})
		});
		map.addOverlay(marker);
	}
	//添加 三角箭头
	function add_Vector(x, y) {
		var vectorFCArrow = new BMap.Marker(new BMap.Point(x, y), {
			icon: new BMap.Symbol(BMap_Symbol_SHAPE_FORWARD_CLOSED_ARROW, {// 初始化方向向上的闭合箭头
				scale: 5,
				strokeWeight: 1,
				rotation: 0,//顺时针旋转30度
				fillColor: 'red',
				fillOpacity: 0.8
			})
		});
		map.addOverlay(vectorFCArrow);
		vectorFCArrow.show();
		//vectorFCArrow.hide()
	}

	var addressInfo;

	function theLocation(x, y, callback) {
		var addressinfo;
		var mpoint = new BMap.Point(x, y);
		var zoom = map.getZoom();
		var marker = new BMap.Marker(mpoint);
		map.centerAndZoom(mpoint, zoom);
		map.addOverlay(marker);

		var myGeo = new BMap.Geocoder({ extensions_town: true });
		myGeo.getLocation(mpoint, function (result) {
			if (result) {
				//alert(result.address);  
				addressInfo = result.address;
				//callback(result.address);
				webcom.mPositioning = result.address;
				webcom.signalPositioning
			}
		});
	}

	function getLocation() {
		return addressInfo;
	}

	//add_Ico(118.801465,31.943004);
	//add_Point(120.60754012414822, 31.30205702705026);
	//add_Vector(118.801465,31.943004);

</script>
<!--

-->